const mysql = require('mysql');

module.exports = (sql,params=[]) =>{
    //1.创建连接对象
    let connection = mysql.createConnection({
        host:'localhost',
        port:'3306',
        user:'root',
        password:'root',
        database:'1708b_address'
    })
    //2.
    connection.connect((error) =>{
        if(error){
            console.log("连接失败")
        }else{
            console.log("连接成功")
        }
    })
    //3.
    return new Promise((resolve,reject) => {
        connection.query(sql,params,(error,data) =>{
            if(error){
                reject(error)
            }else{
                resolve(data)
            }
            //4.关闭链接
            connection.end();
        })
    })
    
}